{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "with open('fujun.csv',mode='w') as file:\n",
    "    name={'name','dept','birthmonth'}\n",
    "    writer=csv.DictWriter(file,fieldnames=name)\n",
    "#     writer.writeheader()\n",
    "    writer.writeheader()\n",
    "    writer.writerow({'name':'夫君','dept':'accouting','birthmonth':'march'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Dialect', 'DictReader', 'DictWriter', 'Error', 'OrderedDict', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONE', 'QUOTE_NONNUMERIC', 'Sniffer', 'StringIO', '_Dialect', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'excel', 'excel_tab', 'field_size_limit', 'get_dialect', 'list_dialects', 're', 'reader', 'register_dialect', 'unix_dialect', 'unregister_dialect', 'writer']\n",
      "OrderedDict([('店铺', 'djldjfl'), ('信息', 'dff'), ('付款人数', '787'), ('价格', '的垃圾分类')])\n"
     ]
    }
   ],
   "source": [
    "import pandas\n",
    "import csv\n",
    "df=open('tb.csv','r')\n",
    "print(dir(csv))\n",
    "\n",
    "res=csv.DictReader(df)\n",
    "\n",
    "for i in res:\n",
    "   print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']\n",
      "<built-in method keys of dict object at 0x000001C71188C948>\n",
      "fujun\n",
      "paly\n"
     ]
    }
   ],
   "source": [
    "d={'f':'fujun','p':'paly'}\n",
    "print(dir(d))\n",
    "print(d.keys)\n",
    "for k in d.values():\n",
    "    print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "with open('tb.csv',mode='w') as file:\n",
    "    name={'信息','价格','付款人数','店铺'}\n",
    "    writer=csv.DictWriter(file,fieldnames=name)\n",
    "#     writer.writeheader()\n",
    "    writer.writeheader()\n",
    "    i=['dff','的垃圾分类','787','djldjfl']\n",
    "   \n",
    "    data={'信息':'{}'.format(i[0]),'价格':'{}'.format(i[1]),'付款人数':'{}'.format(i[2]),'店铺':'{}'.format(i[3])}\n",
    "    writer.writerow(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
